<template>
	<view>
		<view class="list" v-for="item in listt" :key="item.id">
			<view class="left">
				<view class="img">
					<img :src="item.cover" alt="">
				</view>
			</view>
			<view class="right">
				<span>{{item.title}}</span>
				<view class="right-item">
					<span>￥{{item.price}}</span>
					<span>￥{{item.t_price}}</span>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		listGet
	} from "@/api/user.js"
	export default {
		data() {
			return {
				listt: [],
				queryModel: {
					page: 1,
					limit: 10,
				},
				count:0,
			}
		},
		onLoad() {
			this.listtt()
		},
		//下拉刷新
		onPullDownRefresh:function(){
			this.listt=[]
			this.queryModel.page=1
			this.listtt()
		},
		//上拉加载
		onReachBottom: function() {
			console.log('到底了');
			console.log(this.queryModel.page, this.count);
			if (this.queryModel.page < this.count) {
				this.queryModel.page++
				this.listtt()
			} else {
				uni.showToast({
					title: '到最后一页了',
				})
			}
		},
		methods: {
			async listtt() {
				const res = await listGet(this.queryModel)
				if (res.code == "20000") {
					// this.listt = res.data.rows
					this.count = Math.ceil(res.data.count / this.queryModel.limit)
					this.listt = [...this.listt, ...res.data.rows];
				}
			}

		},

	}
</script>

<style scoped lang="scss">
	* {
		box-sizing: border-box;
	}

	.list {
		width: 750rpx;
		height: 180rpx;
		background-color: white;
		display: flex;

		.right {
			width: 400rpx;
			background-color: white;
			height: 180rpx;
			display: flex;
			flex-direction: column;
			justify-content: center;

			span {
				padding-left: 10rpx;
				font-size: 35px;
			}

			.right-item {
				padding-top: 60rpx;
				padding-left: 10rpx;

				span:nth-child(1) {
					color: red;
					font-size: 45rpx
				}

				span:nth-child(2) {
					color: gray;
					font-size: 25rpx
				}
			}
		}

		.left {
			width: 350rpx;
			height: 180rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			background-color: white;

			.img {
				width: 320rpx;
				height: 170rpx;
				background-color: white;

				img {
					width: 320rpx;
					height: 170rpx;
				}
			}
		}
	}
</style>
